namespace ghost
{
    export class GuideTip extends GYSprite
    {        
        private static _instance:GuideTip;
        public static get instance():GuideTip
        {            
            return GuideTip._instance || new GuideTip;
        }
        public step:number=0;
        public circle:GYSeqImage;
        public hand:GYSeqImage;
        private _curTarget:Laya.Sprite;
        constructor()
        {
            super();
            let s= this;
            GuideTip._instance = s;
            s.circle = new GYSeqImage;
            s.circle.y = s.circle.x = -(196 >> 1)
            s.addChild(s.circle);
            s.hand = new GYSeqImage;
            s.hand.y = -116;            
            s.addChild(s.hand);
            s.circle.source = SkinDictionary.getSeqTextures("circle", 16);
            s.hand.source = SkinDictionary.getSeqTextures("mouse", 26);
            s.mouseEnabled = false;
            s.mouseThrough = true;
        }     
        public hide():void
        {
            let s= this;
            if(s.parent)
                s.parent.removeChild(s);
            s.circle.pause();
            s.hand.pause();
            SceneManager.instance.resume();            
        }        
        public addGuide(target:Laya.Sprite=null):boolean
        {
            let s= this;           
            if(Main.curLevelIndex != 1) 
                return;
            if(s.parent && !s.parent._destroyed)
                return;
           

            if(target == null)
            {
                if(s.step == 0 || s.step == 2 || s.step == 6 || s.step == 8)
                {
                    let logic = <CommonScene>SceneManager.instance.sceneLogic;                    
                    let module:Module = Module.getInstance();                    
                    let type:number=0;                
                    if(s.step == 0)
                        type = 1;
                    else if(s.step == 2 && module.callBtn.visible)
                        type = 4;
                    else if(s.step == 6 && logic.doorLvUpBtn.parent)
                        type = 3;
                    else if(s.step == 8 && logic.bedLvUpBtn.parent)
                        type = 2;
                    if(type > 0 && type < 5)
                    {
                        s.circle.start(null);
                        s.hand.start(null);                    
                        SceneManager.instance.pause();
                        if(module.dialogUI == null)
                            module.dialogUI = new DialogUI;
                        module.dialogUI.show(module, true, true, type);
                        ++s.step;
                        return true;
                    }
                }                
                return false;				
            }
            s._curTarget = target;
            s.circle.start(null);
            s.hand.start(null);
            SceneManager.instance.pause();
            target.addChild(s);
            s.x = target.width >> 1;
            s.y = target.height >> 1;
            target.once(Laya.Event.MOUSE_DOWN, s, s.nextGuide);
            target.once(Laya.Event.REMOVED, s, s.hide);
            return true;
        }
        public nextGuide():void
        {
            let s = this;
            if(s._curTarget && !s._curTarget._destroyed)
            {
                s._curTarget.off(Laya.Event.REMOVED, s, s.hide);
                s._curTarget.off(Laya.Event.MOUSE_DOWN, s, s.nextGuide);
                s._curTarget = null;
            }                
            s.hide();
            ++s.step;           
            Laya.timer.once(500, s, ()=>{
                GameDispatcher.instance.event(GameEvent.GUIDE_COMPLETE);
            });            
        }
        public destroy(destroyChild?: boolean): void {
            //禁止销毁引导
        }
    }
}